package com.example.shardingjdbcdemo.service.impl;

import com.example.shardingjdbcdemo.dao.ShardingMapper;
import com.example.shardingjdbcdemo.pojo.ScsProduct;
import com.example.shardingjdbcdemo.service.ShardingService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ShardingServiceImpl implements ShardingService {

    @Resource
    private ShardingMapper shardingMapper;
    @Override
    @Async(value = "taskThread")
//    @Transactional(rollbackFor = {TRANSACTION_REQUIRED.class})
    public void insertProduct(ScsProduct scsProduct) {
        scsProduct.setProductName("小商品系列-sharding-jdbc"+Thread.currentThread().getName());
        shardingMapper.insertProduct(scsProduct);
    }

    @Override
    public List<ScsProduct> queryProduct() {
        return shardingMapper.selectProduct();
    }

    @Override
    public PageInfo<ScsProduct> queryProductPage() {
        Integer pageIndex = 1;
        Integer pageSize = 15;
        PageHelper.startPage(pageIndex,pageSize);
        List<ScsProduct> scsProductList = shardingMapper.selectProduct();
        return new PageInfo<>(scsProductList);
    }

    @Override
    public List<ScsProduct> queryProductByIds(List<Long> ids) {
        return shardingMapper.selectProductByIds(ids);
    }
}

